﻿using UnityEngine;

public class SkillFireBallLogic:SkillLogicBase
{
    protected override void InitTimeLine()
    {
        _timeLine.AddEvent(0, 0, onSkillStart);//技能开始
        _timeLine.AddEvent(0f, 10, onAction);//播放动画
        _timeLine.AddEvent(0.2f, 1, onFlyObject);//生成飞行道具
        _timeLine.AddEvent(1.3f, 10, onActionEnd);//停止动画
        _timeLine.AddEvent(1.3f,0,onSkillEnd);//技能结束
    }

    private void onFlyObject(int flyObjID)
    {
        //Debug.Log("生成飞行道具");
        var flyDB = FlyObjectTable.GetInstance()[flyObjID];
        if (flyDB == null) { Debug.LogError("未找到飞行道具：" + flyObjID);return; }
        var ball = ResManager.GetInstance().load<GameObject>(flyDB.ResPath, _caster.transform.position);
        _caster.transform.LookAt(_caster.CurTarget.transform);
        var flyObject = ball.AddComponent<FlyObject>();
       
        flyObject.Init(_caster,_caster.CurTarget, flyDB.FlySpeed, flyDB.Radius, OnHItSomething);
    }

    private void OnHItSomething(FlyObject flyObject, Creature creature)
    {
        //Debug.Log("击中目标");
        ResManager.GetInstance().Release(flyObject.gameObject);
        DamageMgr.GetInstance().Damage(_caster,creature);
    }
  
}
